//
//  ShengJingMessageViewController+LCAVPlay.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/10/10.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "ShengJingMessageViewController+LCAVPlay.h"
#import "JKSongsMessStatus.h"
#import "NSString+Substring.h"
#import "LCBibleTableViewController.h"

@implementation ShengJingMessageViewController (LCAVPlay)

-(void)creareAVPlay{
    // 安装通知
    [self setupNotifications];
}

- (void)dealloc {
    self.managerShengJingView.hidden = YES;
    [self.managerShengJingView removeAllSubviews];

    [self teardownNotifications];
}
#pragma mark - 通知处理 -
// 安装通知
- (void)setupNotifications {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"PUSHPLAYPAGE" object:nil];
    
    // 1. 安装播放状态发生变化的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(musicPlayerPlayingSongDidChangedNotification:) name:LCMusicPlayerPlayingSongDidChangedNotification object:_LCPlayer];

}

// 卸载通知
- (void)teardownNotifications {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - 通知处理回调
///跳转到播放页
-(void)receiveNotification:(NSNotification *)notification{
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LCPlayStoryboard" bundle:nil];
    UIViewController *controller = [sb instantiateInitialViewController];
    [self presentViewController:controller animated:YES completion:nil];
    
}


///跳转到相关播放页
-(void)musicPlayerPlayingSongDidChangedNotification:(NSNotification *)notification{
    JKSongsMessStatus *playingSong = notification.userInfo[kMusicPlayerPlayingSong];
    NSString *tabNameStr = playingSong.title;
    tabNameStr = [tabNameStr substringWithinBoundsLeft:@"约" right:@"("];
    tabNameStr = [tabNameStr stringByReplacingOccurrencesOfString:@"新约" withString:@""];
    tabNameStr = [tabNameStr stringByReplacingOccurrencesOfString:@"旧约" withString:@""];
    
    if (tabNameStr != nil) {
        self.nameStr = tabNameStr;
        self.tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:tabNameStr];
        [self.nameBtn setTitle:tabNameStr forState:UIControlStateNormal];
 
    }
    tabNameStr = playingSong.title;
    tabNameStr = [tabNameStr substringWithinBoundsLeft:@"第" right:@"章"];
    self.numLabel.text = [NSString stringWithFormat:@"第 %@ 章", tabNameStr];
    [self.countBtn setTitle:[NSString stringWithFormat:@"%@", tabNameStr] forState:UIControlStateNormal];

    [self.shengjingMessageTab reloadData];
    self.bibleTableViewController.currentRow = 0;
    [self.bibleTableViewController.selectedData removeAllObjects];
    [self.bibleTableViewController.indexPathArr removeAllObjects];
}

@end
